<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/include/background.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>微信等信息编辑页面</title>
<link rel="stylesheet" type="text/css" href="<%=css%>/common.css"/>
<link rel="stylesheet" type="text/css" href="<%=css%>/main.css"/>
<script>
$(document).ready(function(){
	//保存按钮
	$("#saveButton").click(function() {
		var content = $("#content").val();
		var id = $("#id").val();
		//ajax提交
		$.ajax({
			url : "<%=pre%>/b_weixin/update<%=suf%>",
			type : 'post',
			dataType : 'html',
			data : {id:id,content:content},
			success : function(data, status) {
				if (status == 'success') {
					if (data == '1') {
						var timer;
						art.dialog({
							content : '<span style="color:#f00">编辑成功！</span>',
							init : function() {
								var that = this, i = 1;
								var fn = function() {
									!i && that.close();
									i--;
								};
								timer = setInterval(fn, 1000);
								fn();
							},
							close : function() {
								clearInterval(timer);
								window.location.href="<%=pre%>/b_weixin/index<%=suf%>";
							}
						}).show();	
					} else {
						art.dialog.tips('<span style="color:#f00">编辑失败！</span>', 1);
					}
				}
			},
			error : function(xhr, textStatus,
					errorThrown) {
				art.dialog.tips('<span style="color:#f00">插入失败！</span>', 1);
			}
		});
	});
	
	//上传图片
	$("#uploadFile").live('change',function(){
		var picFile = $("#uploadFile").val();
		var wjjname = "base";
		if(picFile == ""){
			art.dialog.alert("请选择文件!");
			return;
		}
		else{
			var strFilter = ".jpeg|.gif|.jpg|.png|";
			if(picFile.indexOf(".") > -1){
				var p = picFile.lastIndexOf(".");
				var strPostfix = picFile.substring(p,picFile.length) + '|';
				strPostfix = strPostfix.toLowerCase();
				if(strFilter.indexOf(strPostfix) > -1){
					$.ajaxFileUpload({
						url: '<%=pre%>/b_com/fileupload<%=suf%>', 
						data:{wjjname:wjjname},
						type: 'post',
						fileElementId: 'uploadFile',
						dataType:'json', //返回值类型，一般设置为json、application/json
						success: function(data, status){ 
				            	if(data.ret == 1){
				            		$("#content").val(data.path);
				            		$("#imgContent").attr("src","<%=upload%>/"+ data.path);
				            	}
				            	else{
				            		art.dialog.alert("上传失败！");
				            	}
				            },
				            error: function(data, status, e){ 
				            	art.dialog.tips('<span style="color:#f00">上传失败，请重传！</span>', 1);
				            }
					});
				}else{
					art.dialog.alert("请选择：图片格式的文件！");
				}
			}
		}
	});
	
});
</script>
</head>
<body>
<div class="crumb-wrap">
	<div class="crumb-list">
		<i class="icon-font"></i>
		<a href="index.html">首页</a>
		<span class="crumb-step">&gt;</span>
		<span class="crumb-name">微信等信息管理</span>
		<span class="crumb-step">&gt;</span>
		<span class="crumb-name">编辑</span>
	</div>
</div>
<div class="result-wrap">
	<div class="result-content">
		<input type="hidden" id="id" value="${bean.id }">
		<table class="insert-tab" width="100%">
		<tr>
			<td>${bean.zhname }</td>
			<td>
				<c:choose>
					<c:when test="${bean.name == 'weixin' }">
						<input type="file" name="uploadFile" id="uploadFile">
						<input id="content" type="hidden" value="${bean.content}">
						<img id="imgContent" src="<%=upload%>/${bean.content}" width="100px" height="100px"/>
					</c:when>
					<c:otherwise>
						<input type="text" name="content" id="content" value="${bean.content}" style="width:600px">
					</c:otherwise>
				</c:choose>
				
				
			</td>
		</tr>
		<tr>
			<td>
				<input type="submit" value="保存" class="button" id="saveButton" />
				<a href="<%=pre%>/b_weixin/index<%=suf%>" style="padding-left:10px">返回</a>
			</td>
			<td></td>
		</tr>
	</table>
	</div>
</div>
</body>
</html>